package com.taoxue.dao.impl;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.taoxue.dao.EvaluationDao;
import com.taoxue.model.Evaluation;
@Component
public class EvaluationDaoImpl implements EvaluationDao {
	@Autowired
	private SessionFactory sessionFactory;
	private Log log = LogFactory.getLog(EvaluationDaoImpl.class);
	public void save(Evaluation c) {
		log.debug("Start: EvaluationDaoImpl.save(" + c.toString() + ")");
		sessionFactory.getCurrentSession().saveOrUpdate(c);
		log.info("Done: EvaluationDaoImpl.save(" + c.toString() + ")");
	}
	public void delete(Evaluation c) {
		log.debug("Start: EvaluationDaoImpl.delete(" + c.toString() + ")");
		sessionFactory.getCurrentSession().delete(c);
		log.info("Done: EvaluationDaoImpl.delete(" + c.toString() + ")");
	}
	@SuppressWarnings("unchecked")
	public List<Evaluation> query(String hql) {
		List<Evaluation> list = null;
		log.debug("Start: EvaluationDaoImpl.query(" + hql + ")");
		Query query = sessionFactory.getCurrentSession().createQuery(hql);
		list = query.list();
		if(log.isDebugEnabled()) {
			String result = null;
			for(Evaluation c:list) {
				result += "[ " + c.toString() + " ]\n";
			}
			log.debug("Result: EvaluationDaoImpl.query\n" + result);
		}
		log.info("Done: EvaluationDaoImpl.query(" + hql + ")");
		return list;
	}
}
